from com.Linux.AcquireLinSymInfo import AcquireLinSymInfo


class LoadMsg(AcquireLinSymInfo):
    def __init__(self, hostname, port, name, password):
        # 调用父类的构造器
        super(LoadMsg, self).__init__(hostname, port, name, password)
        # 定义私有成员
        self.__load_msg_dic = super().get_loadBalance()

    # 获取前5，10，15分钟的平均负载百分比
    def get_thrLoadAvgs(self):
        load_avgs_ls = self.__load_msg_dic.get('bef_5min_loadavgs'), self.__load_msg_dic.get(
            'bef_10min_loadavgs'), self.__load_msg_dic.get('bef_15min_loadavgs')
        return load_avgs_ls

    # 获取总线程数和当前使用中的线程数
    def get_threadCount(self):
        using_thread_count = int(self.__load_msg_dic['usingThread_and_totalThread'].split('/')[0])
        total_thread_count = int(self.__load_msg_dic['usingThread_and_totalThread'].split('/')[1])
        return total_thread_count, using_thread_count

    # 获取当前正在使用的线程id
    def get_usingProcess_id(self):
        process_id = int(self.__load_msg_dic['recently_usingThread_id'])
        return process_id
